# Maintainer: Peltoche <dev@halium.fr>
# Co-maintainer: Andrea Pascal <andrea@anodium.net>
# Co-Maintainer: Deeraurty at github

_realname=lsd
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.21.0
pkgrel=1
pkgdesc="The next gen ls command (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://github.com/Peltoche/lsd"
license=("MIT")
makedepends=("${MINGW_PACKAGE_PREFIX}-rust")
#depends=()
#optdepends=('powerline-fonts: powerline symbols for terminals'
#            'nerd-fonts-complete: popular collections such as Font Awesome & fonts such as Hack')
source=("${_realname}-${pkgver}.tar.gz::https://github.com/Peltoche/lsd/archive/refs/tags/${pkgver}.tar.gz")
sha256sums=('f500c18221f9c3fd45f88f6f764001e99cf9d6d74af9172cbb9a9ff32f3e5c7d')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"

  cargo fetch --locked
}

build() {
  cd "${srcdir}/${_realname}-${pkgver}"

  export SHELL_COMPLETIONS_DIR="$PWD/completions"
  cargo build --release --frozen
}

check() {
  cd "${srcdir}/${_realname}-${pkgver}"

  # Unset lower-cased envs temp and tmp
  # that points to AppData/Local/Temp
  # to pass 
  #   - test_list_almost_all_empty_directory 
  #   - test_list_all_empty_directory
  unset temp
  unset tmp

  cargo test --release --frozen
}

package() {
  cd "${srcdir}/${_realname}-${pkgver}"

  cargo install \
    --offline \
    --no-track \
    --frozen \
    --path . \
    --root "${pkgdir}${MINGW_PREFIX}"

  install -Dm644 LICENSE "$pkgdir${MINGW_PREFIX}/share/licenses/$pkgname/LICENSE"
  install -Dm644 completions/_lsd "$pkgdir${MINGW_PREFIX}/share/zsh/site-functions/_lsd"
  install -Dm644 completions/lsd.bash "$pkgdir${MINGW_PREFIX}/share/bash-completion/completions/lsd"
  install -Dm644 completions/lsd.fish "$pkgdir${MINGW_PREFIX}/share/fish/vendor_completions.d/lsd.fish"
}
